home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Samples / SampleCode / BoxTex / Textures.c < prev    next >
Encoding:
Text File  |  1995-06-08  |  3.4 KB  |  119 lines  |  [TEXT/MPCC]

  1. // routines to allow us to put texture maps on a parameterized group
  2. //
  3. // ©1994-95 Apple Computer Inc., All Rights Reserved
  4.  
  5. #include <QuickDraw.h>
  6. #include "QD3D.h"
  7. #include "QD3DGroup.h"
  8. #include "QD3DShader.h"
  9.  
  10.  
  11. #include "PictRead.h"        // this is a library file from QD3D applications folder
  12. #include "Textures.h"
  13.  
  14. TQ3Status AddTextureToGroup( TQ3GroupObject    theGroup, TQ3StoragePixmap *textureImage)
  15. {
  16.     TQ3TextureObject    textureObject;
  17.     TQ3GroupPosition position;
  18.     TQ3Object        firstObject;
  19.     
  20.     textureObject = Q3PixmapTexture_New(textureImage);
  21.     
  22.     if( textureObject ) {
  23.         if( Q3Object_IsType(theGroup, kQ3GroupTypeDisplay) == kQ3True) {
  24.             Q3Group_GetFirstPosition(theGroup, &position);
  25.     
  26.             Q3Group_GetPositionObject(theGroup, position,    &firstObject);
  27.     
  28.             if( Q3Object_IsType(firstObject, kQ3SurfaceShaderTypeTexture) == kQ3True) {
  29.                 TQ3TextureObject    oldTextureObject;
  30.                 TQ3StoragePixmap oldTextureImage;
  31.                         
  32.                 Q3TextureShader_GetTexture(firstObject, &oldTextureObject);
  33.                 Q3PixmapTexture_GetPixmap(oldTextureObject, &oldTextureImage);
  34.                 
  35.                 Q3Object_Dispose(oldTextureObject);
  36.                 Q3TextureShader_SetTexture(firstObject, textureObject);
  37.                 Q3Object_Dispose(textureObject);
  38.             } else {
  39.                 TQ3ShaderObject textureShader;
  40.                 
  41.                 textureShader = Q3TextureShader_New(textureObject);
  42.                 Q3Object_Dispose(textureObject);
  43.                 //Q3Group_SetPositionObject(theGroup, position, theDocument->textureShader);
  44.                 Q3Group_AddObjectBefore(theGroup, position, textureShader);
  45.                 Q3Object_Dispose(textureShader);
  46.             }
  47.             
  48.             Q3Object_Dispose(firstObject);
  49.         } else if( Q3Object_IsType(theGroup, kQ3DisplayGroupTypeOrdered) == kQ3True) {
  50.             TQ3ShaderObject textureShader;
  51.             
  52.             Q3Group_GetFirstPositionOfType(
  53.                 theGroup,
  54.                 kQ3ShapeTypeShader, &position);    
  55.             
  56.             if( position ) {
  57.                 Q3Group_GetPositionObject(theGroup, position,    &firstObject);
  58.     
  59.                 if( Q3Object_IsType(firstObject, kQ3SurfaceShaderTypeTexture) == kQ3True) {
  60.                     TQ3TextureObject    oldTextureObject;
  61.                     TQ3StoragePixmap oldTextureImage;
  62.                     
  63.                     Q3TextureShader_GetTexture(firstObject, &oldTextureObject);
  64.                     Q3PixmapTexture_GetPixmap(oldTextureObject, &oldTextureImage);
  65.                     
  66.                     Q3Object_Dispose(oldTextureObject);
  67.                     Q3TextureShader_SetTexture(firstObject, textureObject);
  68.                     Q3Object_Dispose(textureObject);
  69.                 } else {
  70.                     textureShader = Q3TextureShader_New(textureObject);
  71.                     if( textureShader ) {
  72.                         Q3Object_Dispose(textureObject);
  73.                         Q3Group_SetPositionObject(theGroup, position, textureShader);
  74.                         Q3Object_Dispose(textureShader);
  75.                     } else {
  76.                         return(kQ3Failure);
  77.                     }
  78.                 }
  79.             } else {
  80.                 textureShader = Q3TextureShader_New(textureObject);
  81.                 if( textureShader ) {
  82.                     Q3Object_Dispose(textureObject);
  83.                     Q3Group_AddObject(theGroup, textureShader);
  84.                     Q3Object_Dispose(textureShader);
  85.                 } else {
  86.                     return(kQ3Failure);
  87.                 }
  88.             }
  89.             
  90.         }
  91.     return(kQ3Success);
  92.     } else {
  93.         return(kQ3Failure);
  94.     }
  95. }
  96.  
  97. void PictureFileToPixmap( TQ3StoragePixmap *bMap )
  98. {
  99.     PicHandle             thePicture = nil;
  100.     
  101.     if((thePicture = GetPICTFile()) != NULL ) {
  102.     
  103.         LoadMapPICT( thePicture, 
  104.                      0L,
  105.                      (unsigned long)((**thePicture).picFrame.right - (**thePicture).picFrame.left),
  106.                      (unsigned long)((**thePicture).picFrame.bottom - (**thePicture).picFrame.top),
  107.                      bMap)    ;
  108.         
  109.     }
  110. }
  111.  
  112. void TextureGroup( TQ3GroupObject    theGroup)
  113. {
  114.     TQ3StoragePixmap         myMap ;
  115.     
  116.     PictureFileToPixmap( &myMap ) ;
  117.     if( myMap.image != NULL )
  118.         AddTextureToGroup( theGroup, &myMap ) ;
  119. }